home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nibble Magazine
/
nib16.dsk
/
VISISORT PLUS- SHELLSORT.bas
< prev
Wrap
BASIC Source File
|
2023-02-26
|
964b
|
25 lines
100 HGR : HCOLOR= 3
110 DIM A(100): HOME : VTAB 22: PRINT "CREATING ARRAY": FOR I = 1 TO 100:A(I) = I: NEXT
120 HGR : FOR I = 1 TO 100: HPLOT I,A(I): NEXT
130 HOME : VTAB 22: PRINT "SHUFFLING": FOR I = 1 TO 100:B = INT( RND(1) *100) +1:T = A(B):A(B) = A(I):A(I) = T: NEXT
140 HGR : FOR I = 1 TO 100: HPLOT I,A(I): NEXT
150 N = 100
160 HOME : VTAB 22: PRINT "METZNER SORT": PRINT ""
170 GOSUB 10000
180 PRINT "": HOME : VTAB 22: PRINT "DONE": END
9000 REM METZNER (SHELL) SORT
9001 REM A ARRAY TO SORT
9002 REM N ELEMENTS IN ARRAY
10000 M = N
10010 M = INT(M/2)
10015 VTAB 23: PRINT "M=";M;" "; CHR$(7)
10020 IF M = 0 THEN RETURN
10030 FOR X = 1 TO N -M:H = X
10040 V = H +M: IF A(H) <A(V) THEN 10100
10050 T = A(H):A(H) = A(V):A(V) = T
10060 HCOLOR= 0: HPLOT H,0 TO H,100: HCOLOR= 3: HPLOT H,A(H)
10070 HCOLOR= 0: HPLOT V,0 TO V,100: HCOLOR= 3: HPLOT V,A(V)
10080 H = H -M
10090 IF H > = 1 THEN 10040
10100 NEXT X
10110 GOTO 10010